<!DOCTYPE html>
<html>
<head>
<title>req_assign</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" type="text/css"
	href="/codebase/fonts/font_roboto/roboto.css" />
<link rel="stylesheet" type="text/css" href="/codebase/dhtmlx.css" />

<script>
	var myForm, myGrid, logObj, data, my_form2, formStructure;
	//var dhxWins;
	function doOnLoad() {
		//req_query form setup
		if (myForm) {
			myForm.unload();
			myForm = null;
		}
		myForm = new dhtmlXForm("form_req_query");
		myForm.loadStruct("/common/testmanager/req_query.xml");

		myForm.attachEvent("onButtonClick", function(name) {
			doFormValidate();
			if (name == "req_search") {
				var params = "?params=" + myForm.getItemValue("title_key")+"," + myForm.getItemValue("req_type")+","+myForm.getItemValue("apply_req_organization")
				+ "," + myForm.getItemValue("bug_no")+"," + myForm.getItemValue("req_bill_no");
				//myGrid.clearAll();
				//myGrid.load("req/req_search" + params,callback_load,"json");
				myGrid.clearAndLoad("req/req_search_for_assign" + params,callback_load,"json");
				//myGrid.load("req/req_search" + params,"custom_json");
			}
			if (name == "req_search_reset") {
				myForm.clear();
			}
		});

		//grid setup
		if (myGrid) {
			myGrid.clearAll(true);
		}
		myGrid = new dhtmlXGridObject("grid_req_list");
		//myGrid.loadStruct("/common/testmanager/req_list.xml");
		myGrid.setImagePath("/codebase/imgs/");
		//myGrid.setSkin("dhx_skyblue");
		myGrid.setHeader(",Req ID,需求编号,需求状态,需求主题,需求类型,需求提出部门,要求完成时间,缺陷号");
		myGrid.setInitWidths("25,50,120,100,250,100,100,100,100");
		myGrid.setColAlign("center,center,left,left,left,left,left,left,left");
		myGrid.setColTypes("ra,ro,ed,ro,ed,ro,ed,ro,ro");
		myGrid.setColSorting("str,int,str,str,str,str,str,str,str");
		myGrid.enableAutoWidth(true);
		//myGrid.setColumnIds("first,second");
		myGrid.xml.top = "mytop";
		myGrid.xml.row = "./myrow";
		//myGrid.enableAutoWidth(true);
		//myGrid.enableAutoHeight(true);
		myGrid.init();
		//myGrid.load("/common/testmanager/req_list_test_data.xml", "xml");
		myGrid.attachEvent("onRowSelect",function(rowID,celInd){
		    //alert("The id of the selected row is "+rowID);		    
		    myGrid.cells(rowID,0).setValue("1");
		    
		});

		//open window button setup
		formStructure = null;
		formStructure = [ {
			type : "button",
			name : "assign_btn",
			value : "分配需求"
		} ];
		if (my_form2) {
			my_form2.unload();
			my_form2 = null;
		}
		my_form2 = new dhtmlXForm("form_req_query_btn");
		//my_form2.removeItem("assign_btn");
		my_form2.loadStruct(formStructure);

		my_form2.attachEvent("onButtonClick", function(name) {
			open_req_assign_wind();
			/*	var my_form_req_assign;
				if (my_form_req_assign) {
					my_form_req_assign.unload();
					my_form_req_assign = null;
				}
				my_form_req_assign=new dhtmlXForm("form_req_assign");
				myForm.loadStruct("/common/testmanager/req_assign.xml");
			 */
			/*
			logEvent("onButtonClick event called, item name '" + name
					+ "'<br></br>");
			
			if (name = "req_submit") {
				this.send("req/req_new", "post", function(xml) {
					//alert("Saved");
				});
				//alert("Saved");
			} */
		});

		/* if (dhxWins) {
			dhxWins.unload();
			dhxWins = null;
		} */

	}

	var callback = function() {
		//alert("callback");

		if (arguments[1] == "true") {
			alert("查询成功");
			myForm.reset();
		} else {
			alert("查询成功失败，错误信息：" + arguments[1]);
		}
	}
	
	
	var callback_load = function() {
		//alert("load grid");		
	}
	
	function open_req_assign_wind() {
		//alert("open_req_assign_windows");
		
	
		createWindow();
		
		/*
		var get_row=myGrid.getCheckedRows(0);
		if(get_row==""){
			alert("请先选择一条需求");
		}else{	
		
		var get_req_id=myGrid.cells(get_row,1).getValue();		
		myLayout.cells("a").detachObject(true);		
		 myLayout.attachEvent("onContentLoaded", function(id) {
			var ifr = myLayout.cells("a").getFrame();
			doOnLoad();
		});  
		//myLayout.cells("a").attachURL("/req/req_new", true);		
		myLayout.cells("a").attachURL("/req/req_assign_detail?params="+get_req_id, true);
		
		}*/
	}

	function createWindow() {
		//alert("open_createWindow");
		
		
		var get_row=myGrid.getCheckedRows(0);
		if(get_row==""){
			alert("请先选择一条需求");
		}
		else{
			
			var id = "req_assign_window";
			//
		var w = 1000;
		var h = 500;
		var x = 20;
		var y = 20;
			//
			dhxWins = new dhtmlXWindows();
			//dhxWins.attachViewportTo("content_main");
			 dhxWins.createWindow(id, x, y, w, h);
			dhxWins.window(id).setText("分配需求");

			dhxWins.window(id).denyPark();
			dhxWins.window(id).button("park").hide();
			dhxWins.window(id).setModal(true);
			var get_req_id=myGrid.cells(get_row,1).getValue();			
			//myLayout.cells("a").detachObject(true);
			dhxWins.window(id).attachURL("/req/req_assign_detail?params="+get_req_id);
			dhxWins.attachEvent("onClose", function(win){
			  /*   var ifr = dhxWins.window(id).getFrame();
			    var win_value = ifr.contentWindow.document.getElementById("assign_req_id").innerHTML;
			    //alert("win_value "+win_value);
			    window.location.pathname="/test/test_assign?req_id="+win_value; */
			    var params = "?params=" + myForm.getItemValue("title_key")+"," + myForm.getItemValue("req_type")+","+myForm.getItemValue("apply_req_organization")
				+ "," + myForm.getItemValue("bug_no");
				//myGrid.clearAll();
				//myGrid.load("req/req_search" + params,callback_load,"json");
				myGrid.clearAndLoad("req/req_search_for_assign" + params,callback_load,"json");
			    return true;
			    
			});
		}
	}

	function doFormValidate() {
		myForm.validate();
	}

	function doCustomCss(name, value, res) {
		logEvent("onValidate " + (res ? "Success" : "Error")
				+ " called, item '" + name + "'<br/>");
	}
</script>
</head>
<body onload="doOnLoad();">
	<table id="content_main">
		<tr>
			<td>
				<div id="form_req_query"  ></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="form_req_list" ></div>				
				<div id="grid_req_list"
					style="width: 800px; height: 200px; background-color: white;">
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="form_req_query_btn" ></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="form_req_assign" ></div>
			</td>
		</tr>
	
	</table>
</body>
</html>